<template>
  <div class="home">
    <!-- 轮播图区域 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item
        v-for="(item, index) in swiperList"
        :key="index"
        height="200px"
      >
        <van-image :src="item" />
      </van-swipe-item>
    </van-swipe>
    <!-- 顶部搜索框区域 -->
    <van-search v-model="value" placeholder="请输入搜索关键词" show-action>
      <template #label
        ><span @click="$router.push('/city')">{{localCity.label}}▼</span></template
      >
      <template #action><van-icon name="send-gift" size="30" /></template>
    </van-search>
    <!-- 整租合租区域 -->
    <van-grid :border="false">
      <van-grid-item icon="wap-home-o" text="整租" />
      <van-grid-item icon="friends-o" text="合租" />
      <van-grid-item icon="bulb-o" text="地图找房" />
      <van-grid-item icon="wap-home-o" text="去出租" />
    </van-grid>
    <!-- 租房小组区域 -->
    <div class="group">
      <div class="show">
        <div class="title">
          <h3>租房小组</h3>
          <a href="#">更多</a>
        </div>
      </div>
      <div class="content">
        <div
          class="load-item"
          v-for="(item, index) in contentList"
          :key="index"
        >
          <img :src="'http://liufusong.top:8080' + item.imgSrc" alt="" />
          <div class="item-text">
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getLocalCity } from '@/utils/storage'
import { getSwipers, getGroups } from '@/api/index'
export default {
  name: 'index-page',
  components: {},
  props: {},
  data() {
    return {
      swiperList: [],
      value: '',
      contentList: [],
      localCity: []
    }
  },
  computed: {},
  watch: {},
  async created() {
    const { data } = await getSwipers()
    data.body.forEach((item) => {
      const src = 'http://liufusong.top:8080' + item.imgSrc
      this.swiperList.push(src)
    })
    const res = await getGroups(this.localCity.value)
    this.contentList = [...res.data.body]
    this.localCity = getLocalCity()
    console.log(this.localCity)
  },
  methods: {}
}
</script>

<style scoped lang="less">
.home {
  position: relative;
}
.van-search {
  position: absolute;
  top: 20px;
  left: 15px;
  height: 48px;
  line-height: 48px;
  ::v-deep span {
    height: 30px;
    line-height: 30px;
    padding-right: 5px;
    font-size: 12px;
    border-right: 1px solid #333;
  }
  .van-search__action {
    height: 30px;
    line-height: 30px;
  }
}
.show {
  background-color: #f7f7f7;
}
.group {
  padding: 0 10px;
  .title {
    display: flex;
    justify-content: space-between;
    height: 30px;
    line-height: 30px;
    // flex-wrap: wrap;
    h3 {
      font-size: 15px;
    }
    a {
      font-size: 14px;
      color: #333;
    }
  }
  .content {
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 130px;
    background-color: #f7f7f7;
    flex-wrap: wrap;
    .load-item {
      display: flex;
      justify-content: center;
      align-content: center;
      width: 147px;
      height: 60px;
      line-height: 60px;
      text-align: center;
      margin: 0 0 10px !important;
      padding: 10px 0 0;
      background-color: #fff;
      img {
        width: 43px;
        height: 43px;
        margin-right: 5px;
      }
      .item-text {
        line-height: 32px;
        height: 32px;
        p {
          height: 16px;
        }
      }
    }
  }
}
</style>
